package com.jz.main.io;

public class SubArr {
    public static void main(String[] args) {
//        System.out.println(maxInt(new int[]{1 , 3 , -2 , 3 ,-1, 4, -3, 2}));
        //cur  1   4   2    5   4  8
        //max  1   4   4    5   5
//        System.out.println(maxInt(new int[]{-1 , -3 , -2 , 3 ,-1, 4, -8, 2, 7}));
        //cur  -1   -3   -2   3   2  6  -2  2  9
        //max  -1   -1   -1   3   3  6   6  6  9

        run();
    }

    static int maxInt(int[] arr) {
        int cur = -999;
        int max = -999;
        for (int i = 0; i < arr.length; i++) {
            int val = arr[i];
            if (val >= cur + val) {
                cur = val;
            } else {
                cur = cur + val;
            }
            max = Math.max(max, cur);
        }
        return Math.max(max, cur);
    }
    //
    //

    static void run() {
        final int[] a1 = {1, 3, 5, 7, 9};
        final int[] a2 = {2, 4, 6, 8, 10};
        Object o = new Object();
        Thread a1t = new Thread(() -> {
            for (int i : a1) {
                System.out.println(i);
                synchronized (o) {
                    try {
//                        Thread.sleep(1);
                        o.notifyAll();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        Thread a2t = new Thread(() -> {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i : a2) {
                System.out.println(i);
                synchronized (o) {
                    try {
//                        Thread.sleep(1);
                        o.notifyAll();
                        o.wait(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        a1t.start();
        a2t.start();


    }
}
